<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>结果: {{ question.question_text|truncatechars:50 }}</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <!-- 引入Chart.js -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/qrcode@1.5.1/build/qrcode.min.js"></script>
    <style>
        /* 添加进度条颜色类 */
        .progress-bar-0 {
            background: linear-gradient(90deg, #4e73df, #224abe) !important;
        }

        .progress-bar-1 {
            background: linear-gradient(90deg, #1cc88a, #13855c) !important;
        }

        .progress-bar-2 {
            background: linear-gradient(90deg, #f6c23e, #dda20a) !important;
        }

        .progress-bar-default {
            background: linear-gradient(90deg, #36b9cc, #2a8f9e) !important;
        }

        /* 其他样式保持不变 */
        :root {
            --primary-gradient: linear-gradient(135deg, #4e73df 0%, #224abe 100%);
            --shadow-layer: 0 10px 30px rgba(0, 0, 0, 0.08);
            --transition-default: all 0.3s ease;
        }

        body {
            background-color: #f9fafb;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
            padding-top: 20px;
            padding-bottom: 40px;
        }

        .results-container {
            max-width: 1200px;
            margin: 2rem auto;
            padding: 0 15px;
        }

        .results-card {
            box-shadow: var(--shadow-layer);
            border-radius: 0.75rem;
            overflow: hidden;
            background: white;
            transition: var(--transition-default);
        }

        .results-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.12);
        }

        .card-header {
            background: var(--primary-gradient);
            color: white;
            padding: 1.5rem;
            position: relative;
        }

        .card-header::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: rgba(255, 255, 255, 0.2);
        }

        .card-body {
            padding: 2rem;
        }

        .result-item {
            padding: 1.25rem;
            margin-bottom: 1rem;
            border-radius: 0.5rem;
            background: #f8f9fa;
            transition: var(--transition-default);
            animation: fadeIn 0.3s ease forwards;
            opacity: 0;
            position: relative;
        }

        .result-item:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
        }

        .vote-count {
            background: #e8f0fe;
            color: #1a73e8;
            padding: 0.25rem 0.75rem;
            border-radius: 50px;
            font-weight: 600;
        }

        .chart-container {
            margin: 2rem 0;
            position: relative;
            height: 300px;
        }

        .total-votes {
            padding: 1rem;
            background: #f0f7ff;
            border-radius: 0.5rem;
            margin-top: 2rem;
            text-align: center;
            animation: fadeIn 0.5s ease;
        }

        .action-buttons {
            display: flex;
            gap: 1rem;
            margin-top: 2rem;
            flex-wrap: wrap;
            animation: fadeIn 0.5s ease;
        }

        .btn-vote-again {
            background: var(--primary-gradient);
            border: none;
            color: white;
            padding: 0.75rem 1.5rem;
            border-radius: 50px;
            transition: var(--transition-default);
            font-weight: 500;
            flex: 1;
        }

        .btn-vote-again:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 16px rgba(78, 115, 223, 0.3);
        }

        .btn-back {
            background: white;
            color: #5f6368;
            border: 1px solid #e0e0e0;
            padding: 0.75rem 1.5rem;
            border-radius: 50px;
            transition: var(--transition-default);
            font-weight: 500;
            flex: 1;
        }

        .btn-back:hover {
            background: #f8f9fa;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
        }

        .empty-results {
            padding: 2rem;
            text-align: center;
            background: #f8f9fa;
            border-radius: 0.5rem;
            animation: fadeIn 0.5s ease;
        }

        .winner-badge {
            position: absolute;
            top: -10px;
            right: -10px;
            background: #ffc107;
            color: #212529;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.5rem;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            z-index: 2;
        }

        .sidebar {
            background: #f8f9fa;
            border-radius: 0.75rem;
            padding: 1.5rem;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            height: fit-content;
            position: sticky;
            top: 20px;
        }

        .sidebar-title {
            font-weight: 600;
            margin-bottom: 1.5rem;
            color: #4e73df;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .share-buttons {
            display: flex;
            flex-direction: column;
            gap: 1rem;
        }

        .share-btn {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 0.75rem 1.25rem;
            border-radius: 50px;
            background: white;
            color: #4e73df;
            border: 1px solid #e0e0e0;
            transition: var(--transition-default);
            text-decoration: none;
            font-weight: 500;
            cursor: pointer;
        }

        .share-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            background: #4e73df;
            color: white;
        }

        .share-icon {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(78, 115, 223, 0.1);
            font-size: 1.2rem;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(10px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .result-item:nth-child(1) {
            animation-delay: 0.1s;
        }

        .result-item:nth-child(2) {
            animation-delay: 0.2s;
        }

        .result-item:nth-child(3) {
            animation-delay: 0.3s;
        }

        .result-item:nth-child(4) {
            animation-delay: 0.4s;
        }

        .result-item:nth-child(5) {
            animation-delay: 0.5s;
        }

        @media (max-width: 992px) {
            .sidebar {
                position: static;
                margin-top: 2rem;
            }
        }

        @media (max-width: 576px) {
            .card-body {
                padding: 1.5rem;
            }

            .action-buttons {
                flex-direction: column;
            }

            .btn-vote-again,
            .btn-back {
                width: 100%;
            }
        }

        /* 新增样式 */
        .toast-container {
            position: fixed;
            bottom: 20px;
            right: 20px;
            z-index: 1050;
        }

        .toast {
            background-color: #1cc88a;
            color: white;
            border-radius: 8px;
            padding: 15px 25px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            animation: fadeInToast 0.3s ease-in-out;
        }

        @keyframes fadeInToast {
            from {
                opacity: 0;
                transform: translateY(20px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .modal-content {
            border-radius: 12px;
            overflow: hidden;
        }

        .qrcode-container {
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        #qrcode {
            margin: 15px 0;
            padding: 10px;
            background: white;
        }

        .modal-title {
            color: #4e73df;
            font-weight: 600;
        }

        .btn-close {
            position: absolute;
            top: 20px;
            right: 20px;
        }
        
        /* 微信下载提示样式 */
        .wechat-download {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.7);
            z-index: 1060;
            align-items: center;
            justify-content: center;
        }
        
        .download-content {
            background: white;
            border-radius: 15px;
            padding: 30px;
            text-align: center;
            max-width: 500px;
            width: 90%;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
        }
        
        .download-content h4 {
            color: #333;
            margin-bottom: 20px;
        }
        
        .download-buttons {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin-top: 25px;
        }
        
        .download-btn {
            padding: 10px 20px;
            border-radius: 30px;
            color: white;
            font-weight: 500;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            transition: all 0.3s ease;
        }
        
        .download-btn.android {
            background: linear-gradient(135deg, #1cc88a, #13855c);
        }
        
        .download-btn.ios {
            background: linear-gradient(135deg, #4e73df, #224abe);
        }
        
        .download-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }
        
        .close-download {
            position: absolute;
            top: 15px;
            right: 15px;
            background: none;
            border: none;
            font-size: 24px;
            color: white;
            cursor: pointer;
        }
        
        .wechat-icon {
            font-size: 80px;
            color: #07C160;
            margin-bottom: 20px;
        }
    </style>
</head>

<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-gradient-primary shadow-sm">
        <div class="container">
            <a class="navbar-brand d-flex align-items-center" href="{% url 'polls:index' %}">
                <i class="bi bi-bar-chart-steps me-2"></i>
                <span>投票系统</span>
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'polls:index' %}"><i class="bi bi-house-door me-1"></i> 首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#"><i class="bi bi-plus-circle me-1"></i>创建投票 </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#"><i class="bi bi-graph-up me-1"></i> 投票结果</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#"><i class="bi bi-question-circle me-1"></i> 帮助</a>
                    </li>
                </ul>
                <div class="d-flex">
                    <button class="btn btn-light me-2"><i class="bi bi-box-arrow-in-right me-1"></i> 登录</button>
                </div>
            </div>
        </div>
    </nav>

    <div class="results-container">
        <div class="row">
            <!-- 主内容区 -->
            <div class="col-lg-8">
                <div class="results-card">
                    <div class="card-header">
                        <h1 class="h3 mb-0">{{ question.question_text }}</h1>
                        <p class="mb-0 mt-2 opacity-75">投票结果统计</p>
                    </div>

                    <div class="card-body">
                        {% if question.choices.all %}
                        <!-- 图表容器 -->
                        <div class="chart-container">
                            <canvas id="resultsChart"></canvas>
                        </div>

                        {% for choice in question.choices.all %}
                        <div class="result-item">
                            {% if choice.id == winner_id and question.total_votes > 0 %}
                            <div class="winner-badge">
                                <i class="bi bi-trophy"></i>
                            </div>
                            {% endif %}

                            <div class="d-flex justify-content-between align-items-center mb-2">
                                <h5 class="mb-0 fw-bold">{{ choice.choice_text }}</h5>
                                <span class="vote-count">{{ choice.votes }} 票</span>
                            </div>

                            {% if question.total_votes > 0 %}
                            {% widthratio choice.votes question.total_votes 100 as percentage %}
                            <div class="d-flex align-items-center mt-2">
                                <div class="flex-grow-1 me-2">
                                    <div class="progress" style="height: 8px;">
                                        <div class="progress-bar 
                                                {% if forloop.counter0 == 0 %} progress-bar-0
                                                {% elif forloop.counter0 == 1 %} progress-bar-1
                                                {% elif forloop.counter0 == 2 %} progress-bar-2
                                                {% else %} progress-bar-default
                                                {% endif %}" role="progressbar" @style="width: {{ percentage }}%"
                                            aria-valuenow="{{ percentage }}" aria-valuemin="0" aria-valuemax="100">
                                        </div>
                                    </div>
                                </div>
                                <div class="text-muted small" style="min-width: 60px;">
                                    {{ percentage }}%
                                </div>
                            </div>
                            {% endif %}
                        </div>
                        {% endfor %}

                        <div class="total-votes">
                            <h5 class="fw-bold mb-0">总投票数: <span class="text-primary">{{ question.total_votes }}</span>
                            </h5>
                        </div>
                        {% else %}
                        <div class="empty-results">
                            <div class="mb-3">
                                <i class="bi bi-bar-chart text-muted" style="font-size: 3rem;"></i>
                            </div>
                            <h4 class="fw-bold mb-2">暂无投票记录</h4>
                            <p class="text-muted">还没有人参与此投票</p>
                        </div>
                        {% endif %}

                        <div class="action-buttons">
                            <a href="{% url 'polls:detail' question.id %}" class="btn btn-vote-again">
                                <i class="bi bi-arrow-repeat me-2"></i>再次投票
                            </a>
                            <a href="{% url 'polls:index' %}" class="btn btn-back">
                                <i class="bi bi-list-ul me-2"></i>所有投票
                            </a>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 侧边栏分享区 -->
            <div class="col-lg-4">
                <div class="sidebar">
                    <h5 class="sidebar-title">
                        <i class="bi bi-share"></i>
                        分享投票结果
                    </h5>

                    <div class="share-buttons">
                        <a class="share-btn" id="wechatShareBtn">
                            <span class="share-icon">
                                <i class="bi bi-wechat"></i>
                            </span>
                            <span>微信分享</span>
                        </a>
                        <a href="https://connect.qq.com/widget/shareqq/index.html?url={{ request.build_absolute_uri }}&title={{ question.question_text }}&summary=查看投票结果"
                            target="_blank" class="share-btn">
                            <span class="share-icon">
                                <i class="fab fa-qq"></i> <!-- Font Awesome的QQ图标类名 -->
                            </span>
                            <span>QQ分享</span>
                        </a>
                        <a href="mailto:?subject=投票结果分享&body=我邀请您查看投票结果：{{ question.question_text }}%0D%0A{{ request.build_absolute_uri }}"
                            class="share-btn">
                            <span class="share-icon">
                                <i class="bi bi-envelope"></i>
                            </span>
                            <span>邮件分享</span>
                        </a>
                        <a class="share-btn" id="copyLinkBtn">
                            <span class="share-icon">
                                <i class="bi bi-link-45deg"></i>
                            </span>
                            <span>复制链接</span>
                        </a>
                        <a class="share-btn" id="downloadImageBtn">
                            <span class="share-icon">
                                <i class="bi bi-download"></i>
                            </span>
                            <span>下载图片</span>
                        </a>
                    </div>

                    <div class="mt-4">
                        <h5 class="sidebar-title">
                            <i class="bi bi-graph-up"></i>
                            投票分析
                        </h5>
                        <div class="mt-3">
                            <div class="d-flex justify-content-between mb-2">
                                <span class="text-muted">参与人数</span>
                                <span class="fw-bold">{{ question.total_votes }}</span>
                            </div>
                            <div class="d-flex justify-content-between mb-2">
                                <span class="text-muted">选项数量</span>
                                <span class="fw-bold">{{ question.choices.count }}</span>
                            </div>
                            <div class="d-flex justify-content-between mb-2">
                                <span class="text-muted">创建时间</span>
                                <span class="fw-bold">2025-06-20</span>
                            </div>
                            <div class="d-flex justify-content-between">
                                <span class="text-muted">结束时间</span>
                                <span class="fw-bold">2025-07-20</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 微信下载提示 -->
    <div class="wechat-download" id="wechatDownload">
        <button class="close-download" id="closeDownload">&times;</button>
        <div class="download-content">
            <div class="wechat-icon">
                <i class="bi bi-wechat"></i>
            </div>
            <h4>您尚未安装微信，请下载安装后分享</h4>
            <p>微信是一款跨平台的通讯工具，支持发送语音短信、视频、图片和文字</p>
            
            <div class="download-buttons">
                <a href="https://weixin.qq.com/" target="_blank" class="download-btn android">
                    <i class="bi bi-android"></i> 安卓版下载
                </a>
                <a href="https://apps.apple.com/cn/app/wechat/id414478124" target="_blank" class="download-btn ios">
                    <i class="bi bi-apple"></i> iOS版下载
                </a>
            </div>
        </div>
    </div>

    <!-- 提示信息 -->
    <div class="toast-container">
        <div class="toast" id="copyToast" style="display: none;">
            <div class="toast-body">
                <i class="bi bi-check-circle-fill me-2"></i>链接已复制到剪贴板！
            </div>
        </div>
    </div>

    <!-- 页脚 -->
    <footer class="bg-dark text-white py-5 mt-5">
        <div class="container">
            <div class="row">
                <div class="col-md-4 mb-4">
                    <h5 class="fw-bold mb-3">投票系统</h5>
                    <p class="text-white-50">一个简单高效的在线投票平台，帮助您收集意见、做出决策。</p>
                    <div class="d-flex gap-3 mt-4">
                        <a href="#" class="text-white"><i class="bi bi-facebook fs-5"></i></a>
                        <a href="#" class="text-white"><i class="bi bi-twitter fs-5"></i></a>
                        <a href="#" class="text-white"><i class="bi bi-github fs-5"></i></a>
                        <a href="#" class="text-white"><i class="bi bi-linkedin fs-5"></i></a>
                    </div>
                </div>
                <div class="col-md-2 mb-4">
                    <h6 class="fw-bold mb-3">导航</h6>
                    <ul class="list-unstyled">
                        <li class="mb-2"><a href="{% url 'polls:index' %}"
                                class="text-white-50 text-decoration-none">首页</a></li>
                        <li class="mb-2"><a href="#" class="text-white-50 text-decoration-none">创建投票</a></li>
                        <li class="mb-2"><a href="#" class="text-white-50 text-decoration-none">投票统计</a></li>
                        <li class="mb-2"><a href="#" class="text-white-50 text-decoration-none">帮助中心</a></li>
                    </ul>
                </div>
                <div class="col-md-3 mb-4">
                    <h6 class="fw-bold mb-3">资源</h6>
                    <ul class="list-unstyled">
                        <li class="mb-2"><a href="#" class="text-white-50 text-decoration-none">开发文档</a></li>
                        <li class="mb-2"><a href="#" class="text-white-50 text-decoration-none">API接口</a></li>
                        <li class="mb-2"><a href="#" class="text-white-50 text-decoration-none">使用教程</a></li>
                        <li class="mb-2"><a href="#" class="text-white-50 text-decoration-none">常见问题</a></li>
                    </ul>
                </div>
                <div class="col-md-3 mb-4">
                    <h6 class="fw-bold mb-3">联系我们</h6>
                    <ul class="list-unstyled">
                        <li class="mb-2 d-flex">
                            <i class="bi bi-envelope me-2 text-primary"></i>
                            <span class="text-white-50">contact@123.com</span>
                        </li>
                        <li class="mb-2 d-flex">
                            <i class="bi bi-telephone me-2 text-primary"></i>
                            <span class="text-white-50">+86 123 4567 8901</span>
                        </li>
                        <li class="mb-2 d-flex">
                            <i class="bi bi-geo-alt me-2 text-primary"></i>
                            <span class="text-white-50">海南</span>
                        </li>
                    </ul>
                </div>
            </div>
            <hr class="my-4 bg-white-10">
            <div class="text-center text-white-50">
                <p class="mb-0">© 2025 投票系统. 保留所有权利。</p>
            </div>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.8/dist/chart.umd.min.js"></script>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const ctx = document.getElementById('resultsChart').getContext('2d');

            // 动态生成颜色
            function generateColors(count) {
                const colors = [];
                const baseColors = [
                    'rgba(78, 115, 223, 0.8)',
                    'rgba(28, 200, 138, 0.8)',
                    'rgba(246, 194, 62, 0.8)',
                    'rgba(54, 185, 204, 0.8)',
                    'rgba(231, 74, 59, 0.8)',
                    'rgba(142, 68, 173, 0.8)'
                ];

                for (let i = 0; i < count; i++) {
                    colors.push(baseColors[i % baseColors.length]);
                }

                return colors;
            }

            // 获取服务器传递的数据
            const labels = JSON.parse("{{ chart_labels|escapejs }}");
            const data = JSON.parse("{{ chart_data|escapejs }}");

            if (data.length > 0) {
                const backgroundColors = generateColors(data.length);

                const chart = new Chart(ctx, {
                    type: 'doughnut',
                    data: {
                        labels: labels,
                        datasets: [{
                            data: data,
                            backgroundColor: backgroundColors,
                            borderColor: '#fff',
                            borderWidth: 2
                        }]
                    },
                    options: {
                        responsive: true,
                        maintainAspectRatio: false,
                        plugins: {
                            legend: {
                                position: 'bottom',
                                labels: {
                                    padding: 20,
                                    font: {
                                        size: 12
                                    },
                                    usePointStyle: true,
                                    pointStyle: 'circle'
                                }
                            },
                            tooltip: {
                                callbacks: {
                                    label: function (context) {
                                        const label = context.label || '';
                                        const value = context.raw || 0;
                                        const total = context.chart.data.datasets[0].data.reduce((a, b) => a + b, 0);
                                        const percentage = Math.round((value / total) * 100);
                                        return `${label}: ${value} 票 (${percentage}%)`;
                                    }
                                }
                            }
                        },
                        animation: {
                            animateRotate: true,
                            animateScale: true
                        },
                        cutout: '60%'
                    }
                });
            } else {
                // 没有数据时显示占位文本
                ctx.font = '16px "Microsoft YaHei", sans-serif';
                ctx.textAlign = 'center';
                ctx.textBaseline = 'middle';
                ctx.fillStyle = '#999';
                ctx.fillText('暂无投票数据', ctx.canvas.width / 2, ctx.canvas.height / 2);
            }

            // 微信分享功能 - 直接跳转微信
            const wechatShareBtn = document.getElementById('wechatShareBtn');
            wechatShareBtn.addEventListener('click', function() {
                // 创建分享内容
                const shareTitle = '投票结果分享: ' + "{{ question.question_text|truncatechars:30 }}";
                const shareUrl = window.location.href;
                const shareDesc = '查看完整的投票结果和统计数据';
                
                // 微信分享链接
                const wechatLink = `weixin://dl/chat?shareTitle=${encodeURIComponent(shareTitle)}&shareUrl=${encodeURIComponent(shareUrl)}&shareDesc=${encodeURIComponent(shareDesc)}`;
                
                // 尝试打开微信
                window.location.href = wechatLink;
                
                // 检测是否成功打开微信
                setTimeout(function() {
                    // 如果还在当前页面，说明没有微信
                    if (!document.hidden) {
                        document.getElementById('wechatDownload').style.display = 'flex';
                    }
                }, 2000);
            });
            
            // 关闭微信下载提示
            document.getElementById('closeDownload').addEventListener('click', function() {
                document.getElementById('wechatDownload').style.display = 'none';
            });

            // 复制链接功能
            const copyLinkBtn = document.getElementById('copyLinkBtn');
            copyLinkBtn.addEventListener('click', function () {
                const url = window.location.href;
                navigator.clipboard.writeText(url).then(() => {
                    const toast = document.getElementById('copyToast');
                    toast.style.display = 'block';

                    setTimeout(() => {
                        toast.style.display = 'none';
                    }, 3000);
                });
            });

            // 下载图片功能
            const downloadImageBtn = document.getElementById('downloadImageBtn');
            downloadImageBtn.addEventListener('click', function () {
                const card = document.querySelector('.results-card');

                html2canvas(card, {
                    scale: 2,
                    backgroundColor: '#f9fafb'
                }).then(canvas => {
                    const link = document.createElement('a');
                    link.download = '投票结果.png';
                    link.href = canvas.toDataURL('image/png');
                    link.click();
                });
            });
        });
    </script>
</body>

</html>